MODULE Miller;
(* $!f+ :  (* bei aktivierter Option f FPU-Modul verwenden *)
FROM FPU IMPORT SIN, COS, EXTEND, WHOLE;
*)
FROM MathLib0 IMPORT Sin, Cos;
IMPORT appl, graf, MathLib0, VDI, v, vsl, SysVar, Terminal;

FROM SYSTEM IMPORT CODE;

CONST
(* cStep legt fest, wieviele Punkte berechnet werden,
	 und damit auch, wie lange es dauert *)
(*	 cStep = 0.1; (* schnell, aber ziemlich eckig *) *)
	cStep = 0.03;
(*	 cStep = 0.01; *)
(*	 cStep = 0.005; *)
(*	 cStep = 0.0025; *)
	N = TRUNC (200.0 * MathLib0.pi / cStep + 0.5);

VAR
	hdl,
	ScrW, ScrH: SHORTINT;

PROCEDURE init(): BOOLEAN;
TYPE
	tIn = ARRAY [0..10] OF SHORTINT;
VAR
	in: tIn;
	out: ARRAY [0..56] OF SHORTINT;
	j, w, h: SHORTINT;
BEGIN
	IF appl.init () < 0 THEN RETURN FALSE END;
	(*VDI init*)
	in := tIn{1 BY 10, 2};
	hdl := graf.handle (j, j, j, j);
	v.opnvwk (in, hdl, out);
	IF hdl > 0 THEN
		ScrW := out[0]+1;
		ScrH := out[1]+1;
		RETURN TRUE
	ELSE
		appl.exit;
		RETURN FALSE
	END;
END init;

CONST
	cPoints = 100;
TYPE
	tPoints = ARRAY [0..cPoints-1] OF VDI.tPoint;

PROCEDURE Main;
VAR
	(*$Reg*) w2, (*$Reg*) h2: LONGINT;
(*$Q+*)
	(*$Reg*) a,
	(*$Reg*) b,
	(*$Reg*) t: LONGREAL;
(*$Q=*)
	(*$R+*)i: LONGINT;
	(*$Reg*) j: SHORTINT;
	(*$R+*)T: LONGCARD;
	msg: ARRAY [0..79] OF CHAR;
	Points: tPoints;
BEGIN
	IF init() THEN
		graf.mouseform (graf.Off);
		v.clrwk (hdl);
		w2 := ScrW DIV 2;
		h2 := ScrH DIV 2;
(* $!f- :
		a := FLOAT (w2) / 2.0;
		b := FLOAT (h2) / 1.3;
*)
(* $!f+ :
		a := EXTEND (w2) / 2.0;
		b := EXTEND (h2) / 1.3;
*)
		t := 0.0;
		VOID (vsl.color (hdl, VDI.Black));
		T := SysVar.T200Hz ();
		j := 0;
		FOR i := 0 TO N DO
			INC (t, cStep);
			Points[j] := VDI.tPoint{
(* $!f- :
									w2 + INT (a * (Sin (0.99 * t) - 0.7 * Cos (3.01 * t))),
									h2 + INT (b * (Cos (1.01 * t) + 0.1 * Sin (15.03 * t)))
*)
(* $!f+ :
									w2 + WHOLE (a * (SIN (0.99 * t) - 0.7 * COS (3.01 * t))),
									h2 + WHOLE (b * (COS (1.01 * t) + 0.1 * SIN (15.03 * t)))
*)
								};
			INC (j);
			IF j = cPoints THEN
				v.pline (hdl, cPoints, Points);
				Points[0] := Points[cPoints-1];
				j := 1
			END
		END;
		IF j > 1 THEN
			v.pline (hdl, j, Points);
		END;
		T := SysVar.T200Hz() - T;
		msg := FORM (33C+'H', N, ' Durchl„ufe -> ', T DIV 200, ' sec; ',
								 N*200 DIV T, ' Durchl„ufe/sec'+15C+12C);
		Terminal.WriteString (msg); Terminal.Read (msg[0]);
		graf.mouseform (graf.On);
		v.clsvwk (hdl);
		appl.exit ()
	END;
END Main;

BEGIN
	Main
END Miller.
		
	
	